﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using BestLifePOS_Core.DomainObjects;
using BestLifePOS_Core.Data.Core;
using BestLifePOS_Core.Exceptions.DataBase;
using System.Data;

namespace BestLifePOS_Core.Data.Commands
{
    class BestLifeFranchisePayByFrnIDDataAction : BestLifeDataAction<List<Franchise_Payment>>
    {

         private string GvFrnId;
         private DateTime GvFrom;
         private DateTime GvTo;
         public BestLifeFranchisePayByFrnIDDataAction(string PFrnId, DateTime PFrom, DateTime PTo)
        {
            GvFrnId = PFrnId;
            GvFrom = PFrom;
            GvTo = PTo;
        }

         public override List<Franchise_Payment> Body(SqlConnection PConn)
        {
            try
            {
                List<Franchise_Payment> LvList = new List<Franchise_Payment>();


                SqlCommand LvCommand = new SqlCommand();
                LvCommand.Connection = PConn;
                LvCommand.CommandType = CommandType.StoredProcedure;
                LvCommand.CommandText = "dbo.GetFranchisePayByFrnId";
                LvCommand.Parameters.Add(new SqlParameter("@FrnID", GvFrnId));
                LvCommand.Parameters.Add(new SqlParameter("@From", GvFrom));
                LvCommand.Parameters.Add(new SqlParameter("@To", GvTo));//when passing parameters to the SP

                SqlDataReader LvReader = LvCommand.ExecuteReader();
                while (LvReader.Read())
                {
                    Franchise_Payment LvFrnPay = new Franchise_Payment();
                    LvFrnPay.F_Id = LvReader.GetValue(1).ToString();
                    LvFrnPay.FP_Id = LvReader.GetValue(0).ToString();
                    LvFrnPay.Deposit =decimal.Parse( LvReader.GetValue(2).ToString());
                    LvFrnPay.Balance = decimal.Parse(LvReader.GetValue(3).ToString());
                    LvFrnPay.Payment_Stat = LvReader.GetValue(4).ToString();
                    LvFrnPay.Date_Create =DateTime.Parse( LvReader.GetValue(5).ToString());


                    LvList.Add(LvFrnPay);
                }
                return LvList;
            }
            catch (BestlifeDatabaseException e)
            {
                throw new BestlifeDatabaseException(e);
            }
        }
    }
}
